1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| private void mDraw() { Canvas c = null; try { c = holder.lockCanvas(); if(c == null) return; c.drawColor(Color.WHITE); c.translate(30,10); paint.setAlpha(255); paint.setColor(Color.BLACK); int width = getWidth() - 65; int height = getHeight() - 40; for(int i = 0; i < 7; i ++) c.drawLine(width / 6f * i,0,width / 6f * i,height,paint); for(int i = 0; i < 6; i ++) c.drawLine(0,height / 5f * i,width,height / 5f * i,paint); paint.setTextAlign(Paint.Align.CENTER); for(int i = 0; i < 7; i ++) c.drawText((6-i) + (i==6?"":"0") + (i==0?"seconds":""),width / 6f * i,height+20,paint); paint.setTextAlign(Paint.Align.LEFT); for(int i = 0; i < 6; i ++) c.drawText(2*(5-i) + (i==5?"":"0") + "%",width+5,height / 5f * i,paint); float cy = width; Path path = new Path(); path.moveTo(cy,height);
for(double value : values) { path.lineTo(cy,valueToHeight(height,value)); cy -= pwidth; } path.lineTo(cy+pwidth,height); path.lineTo(width,height); paint.setShader(shader); c.drawPath(path,paint); paint.setShader(null); } catch (Exception e) {
} finally { if(c != null) holder.unlockCanvasAndPost(c); }
}
|